package com.hms.rs.controller;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.hms.services.PatientInfoSrvc;
import com.hms.vo.beans.PatientQueryCriteriaVO;
import com.hms.vo.beans.PatientVO;

@Component
@Path("/ManagePatient")
public class PatientController {

	  private static final Log log = LogFactory.getLog(PatientController.class);
	  
	  @Autowired
	  private PatientInfoSrvc patientInfoSrvc;
	  
	  @POST
	  @Path("/AddPatient")
	  @Consumes({MediaType.APPLICATION_JSON})
	  public String addPatient(PatientVO patientVO) {
		log.debug("Calling addPatient...");
		boolean patientAdded = patientInfoSrvc.addPatient(patientVO);
	    log.debug("Done Calling Patient To Console");
	    return "Done Calling Patient To Console";
	  }
	
	  // This method is called if TEXT_PLAIN is request
	  @POST
	  @Path("/getPatient")
	  @Produces(MediaType.APPLICATION_JSON)
	  public List<PatientVO> getPatient(PatientQueryCriteriaVO ptntQueryCriteria) {
		  log.debug("getPatient() + calling patientInfoSrvc for results...");
		  List<PatientVO> patientQueryResults = patientInfoSrvc.getPatient(ptntQueryCriteria);
		  log.debug("getPatient() + Returning the DB results to UI...");
		  return patientQueryResults;
	  } 
	  
	  /* JAXBContext jaxbContext;
			try {
				System.out.println("From JAXB Try block");
				jaxbContext = JAXBContext.newInstance(Patient.class);
				  javax.xml.bind.Marshaller marshaller = jaxbContext.createMarshaller();
				  //marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
				  marshaller.marshal(ptnt, System.out);
			} catch (JAXBException e) {
				e.printStackTrace();
			}
		  */
		  
	    //return ptnt.toString();
	  /*
	
		  // This method is called if XML is request
	  @GET
	  @Path("/testGetXML")
	  @Produces(MediaType.TEXT_XML)
	  public String sayXMLHello() {
	    return "<?xml version=\"1.0\"?>" + "<hello> Hello Jersey" + "</hello>";
	  }

	  // This method is called if HTML is request
	  @Path("/testGet")
	  @GET
	  @Produces(MediaType.TEXT_HTML)
	  public String sayHtmlHello() {
	    return "<html> " + "<title>" + "Hello TITLE Jersey" + "</title>"
	        + "<body><h1>" + "Hello Sarat's Jersey" + "</body></h1>" + "</html> ";
	  }
	  
	  @Path("/search")
	  @POST
	  @Produces(MediaType.APPLICATION_JSON)
	  public String searchPatient()
	  {
		  return "";
	  }

	public PatientInfoSrvc getPatientInfoSrvc() {
		return patientInfoSrvc;
	  }

	public void setPatientInfoSrvc(PatientInfoSrvc patientInfoSrvc) {
		this.patientInfoSrvc = patientInfoSrvc;
		System.out.println("PatientController.java: Done setting the patientInfoSrvc to... " + patientInfoSrvc);
	}*/
}
